<?php
/**
 * Created by IntelliJ IDEA.
 * User: jimmyhsu
 * Date: 2017/5/15
 * Time: 20:53
 */
date_default_timezone_set("Asia/Shanghai");
$dbhost = "127.0.0.1:3306";
$dbuser = "root";
$dbpass = "1258";
$dbname = "mobike";
$cn = mysqli_connect($dbhost,$dbuser,$dbpass) or die("connect error");
mysqli_select_db($cn, $dbname)or die("db error");
mysqli_query($cn, "set names 'utf8'");
$result = array();

$sql = "select ID, lat, lon, type, age, time from bike";
if ($query = mysqli_query($cn, $sql)) {
    $temp = array();
    while ($row = mysqli_fetch_assoc($query)) {
        $bike_id = $row['ID'];
        $lat = $row['lat'];
        $lon = $row['lon'];
        $type = $row['type'];
        $age = $row['age'];
        $time = $row['time'];
        array_push($temp, array('ID'=>$bike_id, 'lat'=>$lat, 'lon'=>$lon, 'type'=>$type, 'age'=>$age, 'time'=>strtotime($time)));
    }
    $result['data'] = $temp;
    echo json_encode($result);
}